home *** CD-ROM | disk | FTP | other *** search
- /*
- * REALbasic-Plugin for converting Icons to RB-Pictures
- *
- * This code is freeware, you may use and extend it as you like.
- *
- * The enclosed project file was created using CodeWarrior Pro 3.
- *
- * It was written on April 6, 99 by Thomas Tempelmann, <http://www.tempel.org/rb/>
- *
- * Enjoy and contribute!
- */
-
- #include <string.h>
- #include "rb_plugin.h"
-
- static void copyBytes (const char* src, Ptr dest, short n)
- {
- while (n--) {
- *dest++ = *src++;
- }
- }
-
- static REALpicture IconToPict (REALstring iconData, long depth, long size)
- {
- REALpicture p;
- GWorldPtr world;
- Rect r;
- SetRect (&r, 0, 0, size, size);
- NewGWorld (&world, depth, &r, nil, nil, 0);
- PixMapHandle pm = GetGWorldPixMap (world);
- Ptr dest = GetPixBaseAddr (pm);
- const char* src = iconData->CString();
- for (int i = 0; i < size; i++) {
- short n = (size/8)*depth;
- copyBytes (src, dest, n);
- src += n;
- dest += (*pm)->rowBytes & 0x3FFF;
- }
- p = REALBuildPictureFromGWorld (world, true);
- //DisposeGWorld(world);
- return p;
- }
-
-
-
- /*
- static GWorldPtr REALPictToGWorldPtr (REALpicture pic, const Rect &rBounds)
- // this routine is taken from QTEffect.cpp out of the Plugin SDK v3
- {
- GWorldPtr gw;
- CGrafPtr oldPort;
- GDHandle oldDevice;
-
- GetGWorld(&oldPort, &oldDevice);
-
- NewGWorld(&gw, 16, &rBounds, nil, nil, 0);
- LockPixels(GetGWorldPixMap(gw));
-
- SetGWorld(gw, nil);
- EraseRect(&rBounds);
- REALDrawPicturePrimitive(pic, &rBounds, false);
-
- SetGWorld(oldPort, oldDevice);
-
- return gw;
- }
- */
-
- /*
- void (REALpicture pic1)
- {
- REALpictureDescription description;
- int w, h;
- Rect r;
-
- REALLockPictureDescription(pic1, &description);
-
- w = description.width;
- h = description.height;
- SetRect(&r, 0, 0, w, h);
-
- if (description.pictureType == pictureMacintoshGWorld) {
- REALLockObject((REALobject) pic1);
- fGW1 = (GWorldPtr) description.pictureData;
- } else {
- data->pic1 = nil;
- data->fGW1 = REALPictToGWorldPtr(pic1, r);
- }
-
- NewGWorld(&data->fDest, 16, &r, nil, nil, 0);
- data->destPicture = REALBuildPictureFromGWorld(data->fDest, true);
-
- QTEffects_SetUpEffectSequence(data, data->fDest, GetGWorldDevice(data->fDest));
- }
- */
-
- /*
- static REALstring PictToIcon (REALpicture pictData, long depth, long size)
- {
- GWorldPtr world;
- Rect r;
- SetRect (&r, 0, 0, size, size);
- NewGWorld (&world, depth, &r, nil, nil, 0);
- PixMapHandle pm = GetGWorldPixMap (world);
- Ptr dest = GetPixBaseAddr (pm);
- const char* src = iconData->CString();
- for (int i = 0; i < size; i++) {
- short n = (size/8)*depth;
- copyBytes (src, dest, n);
- src += n;
- dest += (*pm)->rowBytes & 0x3FFF;
- }
- return REALBuildPictureFromGWorld (world, true);
- }
- */
-
- REALmethodDefinition methods[] = {
- { (REALproc)IconToPict, nil, "IconToPict(icon as String, bitDepth as Integer, size as Integer) as Picture" },
- // { (REALproc)PictToIcon, nil, "PictToIcon(pict as Picture, bitDepth as Integer, size as Integer) as String" },
- };
-
- short pluginMethods = sizeof(methods) / sizeof(REALmethodDefinition);
-
- void PluginEntry (void)
- {
- for (int i = 0; i < pluginMethods; ++i) {
- REALRegisterMethod (&methods[i]);
- }
- }
-